package org.matrix.base
{

	public class Matrix3D extends Matrix2D
	{
		public function Matrix3D(depth:uint){super(depth);	d3Lenght = d2Lenght * depth;}
		
		override public function get dimensions():uint		{return 3}
		
		internal var d3Lenght:uint;
		internal var d3Index:uint;
		internal var d3Dirty:Boolean;
		internal var d3:Vector.<Vector.<Vector.<Number>>>;
		
		override protected function init():void
		{
			d3 = new Vector.<Vector.<Vector.<Number>>>(depth,true);
			for (var i:uint; i < depth; i++)
			{
				super.init();
				d3[i] = d2;
			}
		}
		
		override public function getElement( ... keys:Array):Number				{return d3[keys.unshift()][keys.unshift()][keys.unshift()]}
		override public function setElement(value:Number, ... keys:Array):void	{d3[keys.unshift()][keys.unshift()][keys.unshift()] = value}
		
		override public function get index():uint	{return d3Index * d2Lenght + super.index}
		
		override protected function validate():void
		{
			if (d2Dirty)
			{
				d2 = d3[d3Index];
				d2Dirty = false;
				d1Dirty = true;
			}
			return super.validate();
		}
		
		protected function d4Inc(recursive:Boolean = false):void
		{
			if (recursive)
				d3Index = 0;
			else
				throw new Error('')
		}
		
		final override protected function d3Inc(recursive:Boolean = false):void
		{
			if (++ d3Index == depth)
				d4Inc(d3Dirty = true);
			if (recursive)
				d2Index = 0;
		}
		
//		protected function d4Dec(recursive:Boolean = false):void 
//		{
//			if (recursive)
//				d3Index = depth -1;
//			else
//				throw new Error('')
//		}
//		final override protected function d3Dec(recursive:Boolean = false):void
//		{
//			if (d3Index -- == 0)
//				d4Dec(d3Dirty = true);
//			if (recursive)
//				d2Index = depth - 1;
//		}

	}
}